package com.lgw.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lgw.demo.dao.IdCardMapper;
import com.lgw.demo.dao.PersonMapper;
import com.lgw.demo.pojo.Person;

import java.util.List;

@Service
public class PersonServiceImpl implements PersonService{

    @Autowired
    PersonMapper personMapper;

    @Autowired
    IdCardMapper idCardMapper;

    @Override
    public List<Person> findAllPerson() {
        return personMapper.findAllPerson2();
    }

    @Override
    public List<Person> searchPersonByName(String name) {
        return personMapper.searchPersonByName(name);
    }

    @Transactional
    @Override
    public int addPerson(Person person) {
//        事物：多个操作同时完成，一个有问题，原来完成的操作要回滚
        int result=idCardMapper.addIdCard(person.getIdcard());
        if(result>0){
            return personMapper.addPerson(person);
        }
        return 0;
    }


}
